//
//  HeroDetailView.m
//  MyDota
//
//  Created by 濮亚军 on 15/12/4.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "HeroDetailView.h"
@interface HeroDetailView()

//所有视图都加在这个view上
@property(nonatomic, strong)UIView *bgView;

//英雄头像
@property(nonatomic, strong)UIImageView *heroIcon;

//英雄名称
@property(nonatomic, strong)UILabel *heroName;

//英雄阵营
@property(nonatomic, strong)UILabel *heroCamp;
@property(nonatomic, strong)UIImageView *heroCampIcon;

//攻击类型
@property(nonatomic, strong)UILabel *ATKType;

//HP,MP
@property(nonatomic, strong)UILabel *HPLength;
@property(nonatomic, strong)UILabel *MPlength;

//攻击力
@property(nonatomic, strong)UIImageView *ATKIcon;
@property(nonatomic, strong)UILabel *ATKLabel;
@property(nonatomic, strong)UILabel *ATK;

//护甲
@property(nonatomic, strong)UIImageView *armorIcon;
@property(nonatomic, strong)UILabel *armorLabel;
@property(nonatomic, strong)UILabel *armor;

//攻击速度
@property(nonatomic, strong)UIImageView *ASPDIcon;
@property(nonatomic, strong)UILabel *ASPDLabel;
@property(nonatomic, strong)UILabel *ASPD;

//初始属性背景
@property(nonatomic, strong)UIView *initialBgView;

//力量
@property(nonatomic, strong)UIImageView *strengthIcon;
@property(nonatomic, strong)UILabel *strengthBg;
@property(nonatomic, strong)UILabel *strength;

//敏捷
@property(nonatomic, strong)UIImageView *dexterityIcon;
@property(nonatomic, strong)UILabel *dexterityBg;
@property(nonatomic, strong)UILabel *dexterity;

//智力
@property(nonatomic, strong)UIImageView *intelligenceIcon;
@property(nonatomic, strong)UILabel *intelligenceBg;
@property(nonatomic, strong)UILabel *intelligence;

//平均攻击力
@property(nonatomic, strong)UIImageView *aveATKIcon;
@property(nonatomic, strong)UILabel *aveATKBg;
@property(nonatomic, strong)UILabel *aveATK;

//护甲
@property(nonatomic, strong)UIImageView *inArmorIcon;
@property(nonatomic, strong)UILabel *inArmorBg;
@property(nonatomic, strong)UILabel *inArmor;

//移动速度
@property(nonatomic, strong)UIImageView *speedIcon;
@property(nonatomic, strong)UILabel *speedBg;
@property(nonatomic, strong)UILabel *speed;

//技能
@property(nonatomic, strong)UIImageView *skillOne;
@property(nonatomic, strong)UILabel *skillOneName;

@property(nonatomic, strong)UIImageView *skillTwo;
@property(nonatomic, strong)UILabel *skillTwoName;

@property(nonatomic, strong)UIImageView *skillThree;
@property(nonatomic, strong)UILabel *skillThreeName;

@property(nonatomic, strong)UIImageView *skillFour;
@property(nonatomic, strong)UILabel *skillFourName;

@end
//设置震动效果
static int numberOfShakes = 6;//震动次数
static float durationOfShake = 0.3f;//震动时间
static float vigourOfShake = 0.06f;//震动幅度
@implementation HeroDetailView
{
    //用来选择阵营图标
    CampState campState;
    
    //背景frame
    CGFloat bgWidth;
    CGFloat bgHeight;
    CGFloat bgY;
    //头像frame
    CGFloat iconWidth;
    CGFloat iconY;
    //名称frame
    CGFloat nameX;
    CGFloat nameY;
    CGFloat nameWidth;
    CGFloat nameHeight;
    
    //阵营frame
    CGFloat campX;
    CGFloat campY;
    CGFloat campWidth;
    CGFloat campHeight;
    
    //攻击类型frame
    CGFloat ATKTypeX;
    CGFloat ATKTypeY;
    CGFloat ATKTypeWidth;
    CGFloat ATKTypeHeight;
    
    //初始血量蓝量条
    CGFloat HPLenghtX;
    CGFloat HPLengthY;
    CGFloat HPLengthWidth;
    CGFloat HPLengthHeight;
    
    //ATKframe
    CGFloat ATKX;
    CGFloat ATKY;
    CGFloat ATKWidth;
    CGFloat ATKHeight;
    
    //armor frame
    CGFloat armorY;
    
    //ASPDframe
    CGFloat ASPDY;
    
    //初始值的背景
    CGFloat initialX;
    CGFloat initialY;
    CGFloat initialWidth;
    CGFloat initialHeight;
    
    //力量
    CGFloat strengthX;
    CGFloat strengthY;
    CGFloat strengthWidth;
    CGFloat strengthHeight;
    
    //敏捷
    CGFloat dexterityY;
    
    //智力
    CGFloat intelligenceY;
    
    //平均攻击
    CGFloat aveATKX;
    
    //技能
    CGFloat skillX;
    CGFloat skillY;
    CGFloat skillWidth;
    CGFloat skillHeight;
    
}
#pragma mark --------重写init方法 自定义view--------
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor colorWithRed:40 / 255.0 green:40 / 255.0 blue:40 / 255.0 alpha:0.5];
        bgWidth = kScreenWidth;
        bgHeight = kScreenHeight * 3 / 5;
        bgY = (frame.size.height - bgHeight) / 2;
        
        //加载所有子视图的背景视图
        self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, bgY, bgWidth, bgHeight)];
        self.bgView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0.7];
        self.bgView.hidden = YES;
        self.bgView.alpha = 0;
        self.bgView.layer.shadowOffset = CGSizeMake(0, 3);
        self.bgView.layer.shadowRadius = 5.0;
        self.bgView.layer.shadowColor = [UIColor blackColor].CGColor;
        self.bgView.layer.shadowOpacity = 0.8;
        [self addSubview:_bgView];
        
        //头像
        iconWidth = kScreenWidth / 4;
        iconY = frame.size.height;
        self.heroIcon = [[UIImageView alloc]initWithFrame:CGRectMake(10 * kHProportion, 10 * kHProportion, iconWidth, iconWidth)];
        self.heroIcon.hidden = YES;
        self.heroIcon.alpha = 0;
        self.heroIcon.backgroundColor = [UIColor redColor];
        [self.bgView addSubview:_heroIcon];
        
        //名称
        nameX = iconWidth + 15 * kWProportion;
        nameWidth = kScreenWidth / 5;
        nameHeight = kScreenWidth / 12;
        nameY = - kScreenWidth / 12;
        self.heroName = [[UILabel alloc]initWithFrame:CGRectMake(nameX, nameY, nameWidth, nameHeight)];
        self.heroName.hidden = YES;
        //self.heroName.backgroundColor = [UIColor redColor];
        self.heroName.textAlignment = NSTextAlignmentCenter;
        self.heroName.font = [UIFont systemFontOfSize:kScreenWidth / 23 weight:1];
        self.heroName.textColor = [UIColor blackColor];
        [self.bgView addSubview:_heroName];
        
        //阵营
        campHeight = kScreenWidth / 12;
        campWidth = kScreenWidth / 5 - campHeight;
        campY = -campHeight;
        campX = iconWidth + 15 * kWProportion + (nameWidth - campWidth);
        self.heroCamp = [[UILabel alloc]initWithFrame:CGRectMake(campX, campY, campWidth, campHeight)];
        self.heroCamp.hidden = YES;
        //self.heroCamp.backgroundColor = [UIColor redColor];
        self.heroCamp.textAlignment = NSTextAlignmentLeft;
        self.heroCamp.textColor = [UIColor blackColor];
        self.heroCamp.font = [UIFont systemFontOfSize:kScreenWidth / 24 weight:0];
        [self.bgView addSubview:_heroCamp];
        
        //阵营图标
        self.heroCampIcon = [[UIImageView alloc]initWithFrame:CGRectMake(iconWidth + 15 * kWProportion, campY, nameWidth - campWidth, campHeight)];
        self.heroCampIcon.hidden = YES;
        //self.heroCampIcon.backgroundColor = [UIColor redColor];
        [self.bgView addSubview:_heroCampIcon];
        
        //攻击类型
        ATKTypeWidth = kScreenWidth / 5;
        ATKTypeHeight = kScreenWidth / 12;
        ATKTypeX = iconWidth + 15 * kWProportion;
        ATKTypeY = 2 * campHeight + 5 * kWProportion;
        self.ATKType = [[UILabel alloc]initWithFrame:CGRectMake(ATKTypeX, -ATKTypeHeight, ATKTypeWidth, ATKTypeHeight)];
        //self.ATKType.backgroundColor = [UIColor redColor];
        self.ATKType.hidden = YES;
        self.ATKType.textAlignment = NSTextAlignmentCenter;
        self.ATKType.textColor = [UIColor blackColor];
        self.ATKType.font = [UIFont systemFontOfSize:kScreenWidth / 20 weight:0];
        [self.bgView addSubview:_ATKType];
        
        //血量 蓝量
        HPLenghtX = iconWidth + 25 * kWProportion + ATKTypeWidth;
        HPLengthY = 10 * kWProportion;
        HPLengthWidth = (bgWidth - iconWidth - ATKTypeWidth - 35 * kWProportion) / 2;
        HPLengthHeight = kScreenWidth / 22;
        self.HPLength = [[UILabel alloc]initWithFrame:CGRectMake(HPLenghtX, HPLengthY, 0, HPLengthHeight)];
        self.HPLength.backgroundColor = [UIColor redColor];
        self.HPLength.layer.masksToBounds = YES;
        self.HPLength.textColor = [UIColor blackColor];
        self.HPLength.textAlignment = NSTextAlignmentCenter;
        self.HPLength.font = [UIFont systemFontOfSize:kScreenWidth / 26 weight:0];
        [self.bgView addSubview:_HPLength];
        
        self.MPlength = [[UILabel alloc]initWithFrame:CGRectMake(HPLenghtX + HPLengthWidth + 5 * kWProportion, HPLengthY, 0, HPLengthHeight)];
        self.MPlength.backgroundColor = [UIColor cyanColor];
        self.MPlength.layer.masksToBounds = YES;
        self.MPlength.textColor = [UIColor blackColor];
        self.MPlength.textAlignment = NSTextAlignmentCenter;
        self.MPlength.font = [UIFont systemFontOfSize:kScreenWidth / 26 weight:0];
        [self.bgView addSubview:_MPlength];
        
        
        //攻击力
        ATKX = HPLenghtX + 10 * kWProportion;
        ATKY = HPLengthY + HPLengthHeight + 5 * kHProportion;
        ATKWidth = HPLengthWidth - 20 * kWProportion;
        ATKHeight = kScreenWidth / 16;
        self.ATKIcon = [[UIImageView alloc]initWithFrame:CGRectMake( ATKX, ATKY, ATKHeight, ATKHeight)];
        //self.ATKIcon.backgroundColor = [UIColor redColor];
        self.ATKIcon.image = [UIImage imageNamed:@"ATK"];
        self.ATKIcon.hidden = YES;
        [self.bgView addSubview:_ATKIcon];
        self.ATKLabel = [[UILabel alloc]initWithFrame:CGRectMake( ATKX + ATKHeight + 5 * kWProportion, ATKY, 2 * ATKHeight, ATKHeight)];
        //self.ATKLabel.backgroundColor = [UIColor redColor];
        self.ATKLabel.text = @"攻击力:";
        self.ATKLabel.hidden = YES;
        self.ATKLabel.textAlignment = NSTextAlignmentLeft;
        self.ATKLabel.textColor = [UIColor blackColor];
        self.ATKLabel.font = [UIFont systemFontOfSize:kScreenWidth / 28];
        [self.bgView addSubview:_ATKLabel];
        self.ATK = [[UILabel alloc]initWithFrame:CGRectMake( ATKX + 3 * ATKHeight + 5 * kWProportion, ATKY, ATKWidth, ATKHeight)];
        //self.ATK.backgroundColor = [UIColor redColor];
        self.ATK.hidden = YES;
        self.ATK.textAlignment = NSTextAlignmentLeft;
        self.ATK.textColor = [UIColor blackColor];
        self.ATK.font = [UIFont systemFontOfSize:kScreenWidth / 28];
        [self.bgView addSubview:_ATK];
        
        //护甲
        armorY = HPLengthY + HPLengthHeight + 5 * kHProportion + ATKHeight;
        self.armorIcon = [[UIImageView alloc]initWithFrame:CGRectMake( ATKX, armorY, ATKHeight, ATKHeight)];
        //self.armorIcon.backgroundColor = [UIColor redColor];
        self.armorIcon.image = [UIImage imageNamed:@"Armor"];
        self.armorIcon.hidden = YES;
        [self.bgView addSubview:_armorIcon];
        self.armorLabel = [[UILabel alloc]initWithFrame:CGRectMake( ATKX + ATKHeight + 5 * kWProportion, armorY, 1.5 * ATKHeight, ATKHeight)];
        //self.armorLabel.backgroundColor = [UIColor redColor];
        self.armorLabel.text = @"护甲:";
        self.armorLabel.hidden = YES;
        self.armorLabel.textAlignment = NSTextAlignmentLeft;
        self.armorLabel.textColor = [UIColor blackColor];
        self.armorLabel.font = [UIFont systemFontOfSize:kScreenWidth / 28];
        [self.bgView addSubview:_armorLabel];
        self.armor = [[UILabel alloc]initWithFrame:CGRectMake( ATKX + 2.5 * ATKHeight + 5 * kWProportion, armorY, ATKWidth, ATKHeight)];
        self.armor.hidden = YES;
        //self.armor.backgroundColor = [UIColor redColor];
        self.armor.textAlignment = NSTextAlignmentLeft;
        self.armor.textColor = [UIColor blackColor];
        self.armor.font = [UIFont systemFontOfSize:kScreenWidth / 28];
        [self.bgView addSubview:_armor];
        
        //攻击速度
        ASPDY = HPLengthY + HPLengthHeight + 5 * kHProportion + 2 * ATKHeight;
        self.ASPDIcon = [[UIImageView alloc]initWithFrame:CGRectMake( ATKX, ASPDY, ATKHeight, ATKHeight)];
        //self.ASPDIcon.backgroundColor = [UIColor redColor];
        self.ASPDIcon.image = [UIImage imageNamed:@"ASPD"];
        self.ASPDIcon.hidden = YES;
        [self.bgView addSubview:_ASPDIcon];
        self.ASPDLabel = [[UILabel alloc]initWithFrame:CGRectMake( ATKX + ATKHeight + 5 * kWProportion, ASPDY, 2.5 * ATKHeight, ATKHeight)];
        //self.ASPDLabel.backgroundColor = [UIColor redColor];
        self.ASPDLabel.text = @"攻击速度:";
        self.ASPDLabel.hidden = YES;
        self.ASPDLabel.textAlignment = NSTextAlignmentLeft;
        self.ASPDLabel.textColor = [UIColor blackColor];
        self.ASPDLabel.font = [UIFont systemFontOfSize:kScreenWidth / 28];
        [self.bgView addSubview:_ASPDLabel];
        self.ASPD = [[UILabel alloc]initWithFrame:CGRectMake( ATKX + 3.5 * ATKHeight + 5 * kWProportion, ASPDY, ATKWidth, ATKHeight)];
        self.ASPD.hidden = YES;
        //self.ASPD.backgroundColor = [UIColor redColor];
        self.ASPD.textAlignment = NSTextAlignmentLeft;
        self.ASPD.textColor = [UIColor blackColor];
        self.ASPD.font = [UIFont systemFontOfSize:kScreenWidth / 28];
        [self.bgView addSubview:_ASPD];
        
        //初始值的背景
        initialX = 20 * kWProportion;
        initialY = self.heroIcon.frame.size.height + 20 * kHProportion;
        initialWidth = (self.bgView.frame.size.width - 40 * kWProportion);
        initialHeight = self.bgView.frame.size.height / 3;
        self.initialBgView = [[UIView alloc]initWithFrame:CGRectMake( initialX, initialY, initialWidth, initialHeight)];
        //self.initialBgView.backgroundColor = [UIColor redColor];
        [self.bgView addSubview:_initialBgView];
        
        //力量
        strengthX = 10 * kWProportion;
        strengthY = 10 * kHProportion;
        strengthWidth = (initialWidth - 30 * kWProportion) / 2;
        strengthHeight = (initialHeight - 30 * kWProportion) / 3;
        self.strengthIcon = [[UIImageView alloc]initWithFrame:CGRectMake(strengthX, strengthY, strengthHeight, strengthHeight)];
        self.strengthIcon.hidden = YES;
        //self.strengthIcon.backgroundColor = [UIColor blackColor];
        self.strengthIcon.image = [UIImage imageNamed:@"Strength"];
        [self.initialBgView addSubview:_strengthIcon];
        
        self.strengthBg = [[UILabel alloc]initWithFrame:CGRectMake(strengthX + strengthHeight, strengthY + strengthHeight / 4, strengthWidth - strengthHeight, strengthHeight / 2)];
        self.strengthBg.hidden = YES;
        self.strengthBg.backgroundColor = [UIColor colorWithRed:130 / 255.0 green:130 / 255.0 blue:130 / 255.0 alpha:0.5];
        self.strengthBg.layer.masksToBounds = YES;
        [self.strengthBg.layer setCornerRadius:8];
        [self.initialBgView addSubview:_strengthBg];
        
        self.strength = [[UILabel alloc]initWithFrame:CGRectMake(strengthX + strengthHeight, strengthY + strengthHeight / 4, 0, strengthHeight / 2)];
        self.strength.backgroundColor = [UIColor orangeColor];
        self.strength.layer.masksToBounds = YES;
        [self.strength.layer setCornerRadius:8];
        self.strength.textAlignment = NSTextAlignmentCenter;
        self.strength.textColor = [UIColor blackColor];
        self.strength.font = [UIFont systemFontOfSize:kScreenWidth / 30];
        [self.initialBgView addSubview:_strength];
        
        //敏捷
        dexterityY = strengthHeight + strengthY + 5 * kHProportion;
        self.dexterityIcon = [[UIImageView alloc]initWithFrame:CGRectMake(strengthX, dexterityY, strengthHeight, strengthHeight)];
        self.dexterityIcon.hidden = YES;
        //self.dexterityIcon.backgroundColor = [UIColor blackColor];
        self.dexterityIcon.image = [UIImage imageNamed:@"Dexterity"];
        [self.initialBgView addSubview:_dexterityIcon];
        
        self.dexterityBg = [[UILabel alloc]initWithFrame:CGRectMake(strengthX + strengthHeight, dexterityY + strengthHeight / 4, strengthWidth - strengthHeight, strengthHeight / 2)];
        self.dexterityBg.hidden = YES;
        self.dexterityBg.backgroundColor = [UIColor colorWithRed:130 / 255.0 green:130 / 255.0 blue:130 / 255.0 alpha:0.5];
        self.dexterityBg.layer.masksToBounds = YES;
        [self.dexterityBg.layer setCornerRadius:8];
        [self.initialBgView addSubview:_dexterityBg];
        
        self.dexterity = [[UILabel alloc]initWithFrame:CGRectMake(strengthX + strengthHeight, dexterityY + strengthHeight / 4, 0, strengthHeight / 2)];
        self.dexterity.backgroundColor = [UIColor greenColor];
        self.dexterity.layer.masksToBounds = YES;
        [self.dexterity.layer setCornerRadius:8];
        self.dexterity.textAlignment = NSTextAlignmentCenter;
        self.dexterity.textColor = [UIColor blackColor];
        self.dexterity.font = [UIFont systemFontOfSize:kScreenWidth / 30];
        [self.initialBgView addSubview:_dexterity];
        
        //智力
        intelligenceY = 2 * strengthHeight + strengthY + 10 * kHProportion;
        self.intelligenceIcon = [[UIImageView alloc]initWithFrame:CGRectMake(strengthX, intelligenceY, strengthHeight, strengthHeight)];
        self.intelligenceIcon.hidden = YES;
        //self.intelligenceIcon.backgroundColor = [UIColor blackColor];
        self.intelligenceIcon.image = [UIImage imageNamed:@"Intelligence"];
        [self.initialBgView addSubview:_intelligenceIcon];
        
        self.intelligenceBg = [[UILabel alloc]initWithFrame:CGRectMake(strengthX + strengthHeight, intelligenceY + strengthHeight / 4, strengthWidth - strengthHeight, strengthHeight / 2)];
        self.intelligenceBg.hidden = YES;
        self.intelligenceBg.backgroundColor = [UIColor colorWithRed:130 / 255.0 green:130 / 255.0 blue:130 / 255.0 alpha:0.5];
        self.intelligenceBg.layer.masksToBounds = YES;
        [self.intelligenceBg.layer setCornerRadius:8];
        [self.initialBgView addSubview:_intelligenceBg];
        
        self.intelligence = [[UILabel alloc]initWithFrame:CGRectMake(strengthX + strengthHeight, intelligenceY + strengthHeight / 4, 0, strengthHeight / 2)];
        self.intelligence.backgroundColor = [UIColor cyanColor];
        self.intelligence.layer.masksToBounds = YES;
        [self.intelligence.layer setCornerRadius:8];
        self.intelligence.textAlignment = NSTextAlignmentCenter;
        self.intelligence.textColor = [UIColor blackColor];
        self.intelligence.font = [UIFont systemFontOfSize:kScreenWidth / 30];
        [self.initialBgView addSubview:_intelligence];
        
        //平均攻击
        aveATKX = strengthX + strengthWidth + 10 * kWProportion;
        self.aveATKIcon = [[UIImageView alloc]initWithFrame:CGRectMake(aveATKX, strengthY, strengthHeight, strengthHeight)];
        self.aveATKIcon.hidden = YES;
        //self.aveATKIcon.backgroundColor = [UIColor blackColor];
        self.aveATKIcon.image = [UIImage imageNamed:@"SATK"];
        [self.initialBgView addSubview:_aveATKIcon];
        
        self.aveATKBg = [[UILabel alloc]initWithFrame:CGRectMake(aveATKX + strengthHeight, strengthY + strengthHeight / 4, strengthWidth - strengthHeight, strengthHeight / 2)];
        self.aveATKBg.hidden = YES;
        self.aveATKBg.backgroundColor = [UIColor colorWithRed:130 / 255.0 green:130 / 255.0 blue:130 / 255.0 alpha:0.5];
        self.aveATKBg.layer.masksToBounds = YES;
        [self.aveATKBg.layer setCornerRadius:8];
        [self.initialBgView addSubview:_aveATKBg];
        
        self.aveATK = [[UILabel alloc]initWithFrame:CGRectMake(aveATKX + strengthHeight, strengthY + strengthHeight / 4, 0, strengthHeight / 2)];
        self.aveATK.backgroundColor = [UIColor redColor];
        self.aveATK.layer.masksToBounds = YES;
        [self.aveATK.layer setCornerRadius:8];
        self.aveATK.textAlignment = NSTextAlignmentCenter;
        self.aveATK.textColor = [UIColor blackColor];
        self.aveATK.font = [UIFont systemFontOfSize:kScreenWidth / 30];
        [self.initialBgView addSubview:_aveATK];
        
        //护甲
        self.inArmorIcon = [[UIImageView alloc]initWithFrame:CGRectMake(aveATKX, dexterityY, strengthHeight, strengthHeight)];
        self.inArmorIcon.hidden = YES;
        //self.inArmorIcon.backgroundColor = [UIColor blackColor];
        self.inArmorIcon.image = [UIImage imageNamed:@"SArmor"];
        [self.initialBgView addSubview:_inArmorIcon];
        
        self.inArmorBg = [[UILabel alloc]initWithFrame:CGRectMake(aveATKX + strengthHeight, dexterityY + strengthHeight / 4, strengthWidth - strengthHeight, strengthHeight / 2)];
        self.inArmorBg.hidden = YES;
        self.inArmorBg.backgroundColor = [UIColor colorWithRed:130 / 255.0 green:130 / 255.0 blue:130 / 255.0 alpha:0.5];
        self.inArmorBg.layer.masksToBounds = YES;
        [self.inArmorBg.layer setCornerRadius:8];
        [self.initialBgView addSubview:_inArmorBg];
        
        self.inArmor = [[UILabel alloc]initWithFrame:CGRectMake(aveATKX + strengthHeight, dexterityY + strengthHeight / 4, 0, strengthHeight / 2)];
        self.inArmor.backgroundColor = [UIColor grayColor];
        self.inArmor.layer.masksToBounds = YES;
        [self.inArmor.layer setCornerRadius:8];
        self.inArmor.textAlignment = NSTextAlignmentCenter;
        self.inArmor.textColor = [UIColor blackColor];
        self.inArmor.font = [UIFont systemFontOfSize:kScreenWidth / 30];
        [self.initialBgView addSubview:_inArmor];

        //智力
        self.speedIcon = [[UIImageView alloc]initWithFrame:CGRectMake(aveATKX, intelligenceY, strengthHeight, strengthHeight)];
        self.speedIcon.hidden = YES;
        //self.speedIcon.backgroundColor = [UIColor blackColor];
        self.speedIcon.image = [UIImage imageNamed:@"Speed"];
        [self.initialBgView addSubview:_speedIcon];
        
        self.speedBg = [[UILabel alloc]initWithFrame:CGRectMake(aveATKX + strengthHeight, intelligenceY + strengthHeight / 4, strengthWidth - strengthHeight, strengthHeight / 2)];
        self.speedBg.hidden = YES;
        self.speedBg.backgroundColor = [UIColor colorWithRed:130 / 255.0 green:130 / 255.0 blue:130 / 255.0 alpha:0.5];
        self.speedBg.layer.masksToBounds = YES;
        [self.speedBg.layer setCornerRadius:8];
        [self.initialBgView addSubview:_speedBg];
        
        self.speed = [[UILabel alloc]initWithFrame:CGRectMake(aveATKX + strengthHeight, intelligenceY + strengthHeight / 4, 0, strengthHeight / 2)];
        self.speed.backgroundColor = [UIColor whiteColor];
        self.speed.layer.masksToBounds = YES;
        [self.speed.layer setCornerRadius:8];
        self.speed.textAlignment = NSTextAlignmentCenter;
        self.speed.textColor = [UIColor blackColor];
        self.speed.font = [UIFont systemFontOfSize:kScreenWidth / 30];
        [self.initialBgView addSubview:_speed];
        
        //技能
        skillX = 10 * kWProportion;
        skillY = initialY + initialHeight + 5 * kHProportion;
        skillWidth = (bgWidth - 35 * kWProportion) / 4;
        self.skillOne = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth , skillY, skillWidth, skillWidth)];
        //self.skillOne.backgroundColor = [UIColor redColor];
        self.skillOne.hidden = YES;
        [self.bgView addSubview:_skillOne];
        
        self.skillOneName = [[UILabel alloc]initWithFrame:CGRectMake(skillX, skillY + skillWidth, skillWidth, skillWidth / 4)];
        self.skillOneName.hidden = YES;
        //self.skillOneName.backgroundColor = [UIColor blackColor];
        self.skillOneName.textAlignment = NSTextAlignmentCenter;
        self.skillOneName.textColor = [UIColor blackColor];
        self.skillOneName.font = [UIFont systemFontOfSize:kScreenWidth / 26];
        [self.bgView addSubview:_skillOneName];
        
        self.skillTwo = [[UIImageView alloc]initWithFrame:CGRectMake(skillX + skillWidth + 5 * kWProportion, kScreenHeight, skillWidth, skillWidth)];
        self.skillTwo.hidden = YES;
        //self.skillTwo.backgroundColor = [UIColor redColor];
        [self.bgView addSubview:_skillTwo];
        
        self.skillTwoName = [[UILabel alloc]initWithFrame:CGRectMake(skillX + skillWidth + 5 * kWProportion, skillY + skillWidth, skillWidth, skillWidth / 4)];
        self.skillTwoName.hidden = YES;
        //self.skillTwoName.backgroundColor = [UIColor blackColor];
        self.skillTwoName.textAlignment = NSTextAlignmentCenter;
        self.skillTwoName.textColor = [UIColor blackColor];
        self.skillTwoName.font = [UIFont systemFontOfSize:kScreenWidth / 26];
        [self.bgView addSubview:_skillTwoName];
        
        self.skillThree = [[UIImageView alloc]initWithFrame:CGRectMake(skillX + 2 * skillWidth + 10 * kWProportion, -skillWidth - bgHeight, skillWidth, skillWidth)];
        self.skillThree.hidden = YES;
        //self.skillThree.backgroundColor = [UIColor redColor];
        [self.bgView addSubview:_skillThree];
        
        self.skillThreeName = [[UILabel alloc]initWithFrame:CGRectMake(skillX + 2 * skillWidth + 10 * kWProportion, skillY + skillWidth, skillWidth, skillWidth / 4)];
        self.skillThreeName.hidden = YES;
        //self.skillThreeName.backgroundColor = [UIColor blackColor];
        self.skillThreeName.textAlignment = NSTextAlignmentCenter;
        self.skillThreeName.textColor = [UIColor blackColor];
        self.skillThreeName.font = [UIFont systemFontOfSize:kScreenWidth / 26];
        [self.bgView addSubview:_skillThreeName];
        
        self.skillFour = [[UIImageView alloc]initWithFrame:CGRectMake(-skillWidth, skillY, skillWidth, skillWidth)];
        self.skillFour.hidden = YES;
        //self.skillFour.backgroundColor = [UIColor redColor];
        [self.bgView addSubview:_skillFour];
        
        self.skillFourName = [[UILabel alloc]initWithFrame:CGRectMake(skillX + 3 * skillWidth + 15 * kWProportion, skillY + skillWidth, skillWidth, skillWidth / 4)];
        self.skillFourName.hidden = YES;
        //self.skillFourName.backgroundColor = [UIColor blackColor];
        self.skillFourName.textAlignment = NSTextAlignmentCenter;
        self.skillFourName.textColor = [UIColor blackColor];
        self.skillFourName.font = [UIFont systemFontOfSize:kScreenWidth / 26];
        [self.bgView addSubview:_skillFourName];
        
    }
    return self;
}
#pragma mark --------给视图赋值--------
-(void)setHeroModel:(HeroModel *)heroModel
{
    _heroModel = heroModel;
    //给头像赋值
    [self.heroIcon sd_setImageWithURL:[NSURL URLWithString:heroModel.heroIcon]];
    
    //英雄名称
    self.heroName.text = heroModel.heroName;
    
    //阵营
    self.heroCamp.text = heroModel.heroCamp;
    if ([heroModel.heroCamp isEqualToString:@"夜魇"])
    {
        //夜魇
        campState = direCamp;
    }
    else
    {
        //天辉
        campState = radiantCamp;
    }
    //给阵营赋值图片
    switch (campState)
    {
        case direCamp:
            self.heroCampIcon.image = [UIImage imageNamed:@"dire"];
            break;
            
        case radiantCamp:
            self.heroCampIcon.image = [UIImage imageNamed:@"radiant"];
            break;
            
        default:
            break;
    }
    
    //攻击类型
    self.ATKType.text = heroModel.positionArray[1];
    
    //HP MPf赋值
    self.HPLength.text = [NSString stringWithFormat:@"HP:%@", heroModel.heroHP];
    self.MPlength.text = [NSString stringWithFormat:@"HP:%@", heroModel.heroMP];
    
    //攻击力赋值
    self.ATK.text = heroModel.heroATK;
    self.armor.text = [NSString stringWithFormat:@"%.f", heroModel.heroArmor];
    
    //攻击速度
    self.ASPD.text = [NSString stringWithFormat:@"%ld", (long)heroModel.heroASPD];
    
    //力量 敏捷 智力
    self.strength.text = [NSString stringWithFormat:@"%.f+(%.2f)", heroModel.heroStrength, heroModel.heroAddSt];
    self.dexterity.text = [NSString stringWithFormat:@"%.f+(%.2f)", heroModel.heroDexterity, heroModel.heroAddDe];
    self.intelligence.text = [NSString stringWithFormat:@"%.f+(%.2f)", heroModel.heroIntelligence, heroModel.heroAddIn];
    
    //攻击力 护甲 移动速度
    self.aveATK.text = [NSString stringWithFormat:@"%.f", heroModel.heroAveATK];
    self.inArmor.text = [NSString stringWithFormat:@"%.f", heroModel.heroArmor];
    self.speed.text = [NSString stringWithFormat:@"%ld", (long)heroModel.heroSpeed];
    
    //技能赋值
    [self.skillOne sd_setImageWithURL:[NSURL URLWithString:heroModel.heroSkillOneIcon]];
    self.skillOneName.text = heroModel.heroSkillOneName;
    
    [self.skillTwo sd_setImageWithURL:[NSURL URLWithString:heroModel.heroSkillTwoIcon]];
    self.skillTwoName.text = heroModel.heroSkillTwoName;
    
    [self.skillThree sd_setImageWithURL:[NSURL URLWithString:heroModel.heroSkillThreeIcon]];
    self.skillThreeName.text = heroModel.heroSkillThreeName;

    [self.skillFour sd_setImageWithURL:[NSURL URLWithString:heroModel.heroSkillFourIcon]];
    self.skillFourName.text = heroModel.heroSkillFourName;

}
#pragma mark --------加载的动画--------
-(void)shows
{
    //动画效果
    [UIView animateWithDuration:1 animations:^{
        //背景
        self.bgView.hidden = NO;
        self.bgView.alpha = 1;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 animations:^{
            //英雄头像
            self.heroIcon.hidden = NO;
            self.heroIcon.alpha = 1;
        } completion:^(BOOL finished) {
            //CAKeyframeAnimation *heroSkillImage3Anim = [self shakeAnimation:_heroIcon.layer.frame];
            //[_heroIcon.layer addAnimation:heroSkillImage3Anim forKey:kCATransition];
            [UIView animateWithDuration:0.1 animations:^{
                //英雄名
                self.heroName.hidden = NO;
                self.heroName.frame = CGRectMake(nameX, 10 * kHProportion, nameWidth, nameHeight);
            } completion:^(BOOL finished) {
                [UIView animateWithDuration:0.1 animations:^{
                    //阵营图标
                    self.heroCampIcon.hidden = NO;
                    self.heroCampIcon.frame = CGRectMake(iconWidth + 15 * kWProportion, nameHeight + 5 * kWProportion, nameWidth - campWidth, campHeight);
                } completion:^(BOOL finished) {
                    [UIView animateWithDuration:0.1 animations:^{
                        //阵营
                        self.heroCamp.hidden = NO;
                        self.heroCamp.frame = CGRectMake(campX, nameHeight + 5 * kWProportion, campWidth, campHeight);
                    } completion:^(BOOL finished) {
                        [UIView animateWithDuration:0.1 animations:^{
                            //攻击类型
                            self.ATKType.hidden = NO;
                            self.ATKType.frame = CGRectMake(ATKTypeX, ATKTypeY, ATKTypeWidth, ATKTypeHeight);
                        } completion:^(BOOL finished) {
                            [UIView animateWithDuration:1 animations:^{
                                //血 蓝
                                self.HPLength.frame = CGRectMake(HPLenghtX, HPLengthY, HPLengthWidth, HPLengthHeight);
                                self.MPlength.frame = CGRectMake(HPLenghtX + HPLengthWidth + 5 * kWProportion, HPLengthY, HPLengthWidth, HPLengthHeight);
                            }];
                            [UIView animateWithDuration:0.1 animations:^{
                                //攻击 护甲 攻击速度
                                self.ATKIcon.hidden = NO;
                                self.ATKLabel.hidden = NO;
                                self.ATK.hidden = NO;
                                self.armorIcon.hidden = NO;
                                self.armorLabel.hidden = NO;
                                self.armor.hidden = NO;
                                self.ASPDIcon.hidden = NO;
                                self.ASPDLabel.hidden = NO;
                                self.ASPD.hidden = NO;
                                
                                //初始值
                                self.strengthIcon.hidden = NO;
                                self.strengthBg.hidden = NO;
                                self.dexterityIcon.hidden = NO;
                                self.dexterityBg.hidden = NO;
                                self.intelligenceIcon.hidden = NO;
                                self.intelligenceBg.hidden = NO;
                                self.aveATKIcon.hidden = NO;
                                self.aveATKBg.hidden = NO;
                                self.inArmorIcon.hidden = NO;
                                self.inArmorBg.hidden = NO;
                                self.speedIcon.hidden = NO;
                                self.speedBg.hidden = NO;
                            } completion:^(BOOL finished) {
                                [UIView animateWithDuration:1 animations:^{
                                    //力量敏捷智力
                                    self.strength.frame = CGRectMake(strengthX + strengthHeight, strengthY + strengthHeight / 4, (strengthWidth - strengthHeight) * (self.heroModel.heroStrength / kStrength), strengthHeight / 2);
                                    self.dexterity.frame = CGRectMake(strengthX + strengthHeight, dexterityY + strengthHeight / 4, (strengthWidth - strengthHeight) * (self.heroModel.heroDexterity / kDexterity), strengthHeight / 2);
                                    self.intelligence.frame = CGRectMake(strengthX + strengthHeight, intelligenceY + strengthHeight / 4, (strengthWidth - strengthHeight) * (self.heroModel.heroIntelligence / kIntelligence), strengthHeight / 2);
                                    
                                    //攻击力 护甲 移速
                                    self.aveATK.frame = CGRectMake(aveATKX + strengthHeight, strengthY + strengthHeight / 4, (strengthWidth - strengthHeight) * (self.heroModel.heroAveATK / kATK), strengthHeight / 2);
                                    self.inArmor.frame = CGRectMake(aveATKX + strengthHeight, dexterityY + strengthHeight / 4, (strengthWidth - strengthHeight) * (self.heroModel.heroArmor / kArmor), strengthHeight / 2);
                                    self.speed.frame = CGRectMake(aveATKX + strengthHeight, intelligenceY + strengthHeight / 4, (strengthWidth - strengthHeight) * ((CGFloat )self.heroModel.heroSpeed / kSpeed), strengthHeight / 2);
                                    
                                    //技能
                                    self.skillOne.hidden = NO;
                                    self.skillTwo.hidden = NO;
                                    self.skillThree.hidden = NO;
                                    self.skillFour.hidden = NO;
                                } completion:^(BOOL finished) {
                                    [UIView animateWithDuration:0.1 animations:^{
                                        self.skillOne.frame = CGRectMake(skillX, skillY, skillWidth, skillWidth);
                                        CAKeyframeAnimation *SkillOneAnim = [self shakeAnimation:_skillOne.layer.frame];
                                        [_skillOne.layer addAnimation:SkillOneAnim forKey:kCATransition];
                                    } completion:^(BOOL finished) {
                                        self.skillOneName.hidden = NO;
                                        [UIView animateWithDuration:0.1 animations:^{
                                            self.skillTwo.frame = CGRectMake(skillX  + 1 * skillWidth + 5 * kWProportion, skillY, skillWidth, skillWidth);
                                            CAKeyframeAnimation *SkillTwoAnim = [self shakeAnimation:_skillTwo.layer.frame];
                                            [_skillTwo.layer addAnimation:SkillTwoAnim forKey:kCATransition];
                                        } completion:^(BOOL finished) {
                                            self.skillTwoName.hidden = NO;
                                           [UIView animateWithDuration:0.1 animations:^{
                                               self.skillThree.frame = CGRectMake(skillX  + 2 * skillWidth + 10 * kWProportion, skillY, skillWidth, skillWidth);
                                               CAKeyframeAnimation *SkillThreeAnim = [self shakeAnimation:_skillThree.layer.frame];
                                               [_skillThree.layer addAnimation:SkillThreeAnim forKey:kCATransition];
                                           } completion:^(BOOL finished) {
                                               self.skillThreeName.hidden = NO;
                                               [UIView animateWithDuration:0.1 animations:^{
                                                   self.skillFour.frame = CGRectMake(skillX  + 3 * skillWidth + 15 * kWProportion, skillY, skillWidth, skillWidth);
                                                   CAKeyframeAnimation *SkillFourAnim = [self shakeAnimation:_skillFour.layer.frame];
                                                   [_skillFour.layer addAnimation:SkillFourAnim forKey:kCATransition];
                                               } completion:^(BOOL finished) {
                                                   self.skillFourName.hidden = NO;
                                               }];
                                           }];
                                        }];
                                    }];
                                }];
                            }];
                        }];
                    }];
                }];
              
            }];
        }];
    }];
}
#pragma mark --------所有子视图回到最初位置--------
-(void)hidden
{
    //背景返回最初frame
    self.bgView.hidden = YES;
    self.bgView.alpha = 0;
    
    //头像返回最初frame
    self.heroIcon.alpha = 0;
    self.heroIcon.hidden = YES;
    
    //名称返回最初frame
    self.heroName.frame = CGRectMake(nameX, nameY, nameWidth, nameHeight);
    self.heroName.hidden = YES;
    
    //阵营返回最初frame
    self.heroCamp.frame = CGRectMake(campX, campY, campWidth, campHeight);
    self.heroCamp.hidden = YES;
    self.heroCampIcon.frame = CGRectMake(iconWidth + 15 * kWProportion, campY, nameWidth - campWidth, campHeight);
    self.heroCampIcon.hidden = YES;
    
    //攻击类型
    self.ATKType.frame = CGRectMake(ATKTypeX, -ATKTypeHeight, ATKTypeWidth, ATKTypeHeight);
    self.ATKType.hidden = YES;
    
    //MP HP
    self.HPLength.frame = CGRectMake(HPLenghtX, HPLengthY, 0, HPLengthHeight);
    self.MPlength.frame = CGRectMake(HPLenghtX + HPLengthWidth + 5 * kWProportion, HPLengthY, 0, HPLengthHeight);
    
    //护甲攻击力还原
    self.ATKIcon.hidden = YES;
    self.ATKLabel.hidden = YES;
    self.ATK.hidden = YES;
    self.armorIcon.hidden = YES;
    self.armorLabel.hidden = YES;
    self.armor.hidden = YES;
    self.ASPDIcon.hidden = YES;
    self.ASPDLabel.hidden = YES;
    self.ASPD.hidden = YES;
    
    //初始属性复原
    self.strengthIcon.hidden = YES;
    self.strengthBg.hidden = YES;
    self.strength.frame = CGRectMake(strengthX + strengthHeight, strengthY + strengthHeight / 4, 0, strengthHeight / 2);
    
    self.dexterityIcon.hidden = YES;
    self.dexterityBg.hidden = YES;
    self.dexterity.frame = CGRectMake(strengthX + strengthHeight, dexterityY + strengthHeight / 4, 0, strengthHeight / 2);
    
    self.intelligenceIcon.hidden = YES;
    self.intelligenceBg.hidden = YES;
    self.intelligence.frame = CGRectMake(strengthX + strengthHeight, intelligenceY + strengthHeight / 4, 0, strengthHeight / 2);
    
    self.aveATKIcon.hidden = YES;
    self.aveATKBg.hidden = YES;
    self.aveATK.frame = CGRectMake(aveATKX + strengthHeight, strengthY + strengthHeight / 4, 0, strengthHeight / 2);
    
    self.inArmorIcon.hidden = YES;
    self.inArmorBg.hidden = YES;
    self.inArmor.frame = CGRectMake(aveATKX + strengthHeight, dexterityY + strengthHeight / 4, 0, strengthHeight / 2);
    
    self.speedIcon.hidden = YES;
    self.speedBg.hidden = YES;
    self.speed.frame = CGRectMake(aveATKX + strengthHeight, intelligenceY + strengthHeight / 4, 0, strengthHeight / 2);
    
    //技能
    self.skillOne.hidden = YES;
    self.skillTwo.hidden = YES;
    self.skillThree.hidden = YES;
    self.skillFour.hidden = YES;
    self.skillOne.frame = CGRectMake(kScreenWidth, skillY, skillWidth, skillWidth);
    self.skillTwo.frame = CGRectMake(skillX + skillWidth + 5 * kWProportion, kScreenHeight, skillWidth, skillWidth);
    self.skillThree.frame = CGRectMake(skillX + 2 * skillWidth + 10 * kWProportion, -skillWidth - bgHeight, skillWidth, skillWidth);
    self.skillFour.frame = CGRectMake(-skillWidth, skillY, skillWidth, skillWidth);
    
    self.skillOneName.hidden = YES;
    self.skillTwoName.hidden = YES;
    self.skillThreeName.hidden = YES;
    self.skillFourName.hidden = YES;
    
}


#pragma mark --------震动动画效果--------
- (CAKeyframeAnimation *)shakeAnimation:(CGRect)frame
{
    CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    
    CGMutablePathRef shakePath = CGPathCreateMutable();
    CGPathMoveToPoint(shakePath, NULL, CGRectGetMidX(frame), CGRectGetMidY(frame));
    for (int index = 0; index < numberOfShakes; ++index)
    {
        CGPathAddLineToPoint(shakePath, NULL, CGRectGetMidX(frame) - frame.size.width * vigourOfShake,CGRectGetMidY(frame));
        CGPathAddLineToPoint(shakePath, NULL,  CGRectGetMidX(frame) + frame.size.width * vigourOfShake,CGRectGetMidY(frame));
    }
    CGPathCloseSubpath(shakePath);
    shakeAnimation.path = shakePath;
    shakeAnimation.duration = durationOfShake;
    CFRelease(shakePath);
    return shakeAnimation;
}

@end
